

f = open('user','r')
users ={}
for user in f:
    user = user.split()
    users = {
        user[1]:user
    }

while True:
    username = input('请输入用户名').strip()

    if username not in users:
        print('该用户未注册')
        continue
    elif users[username][3] == '1': #代表此用户被锁定
        print('该用户已被锁定,请联系管理员')
        continue

    errMaxCount = 3 #错误次数
    while  errMaxCount!=0:

        pwd = input('请输入密码').strip()

        if pwd == users[username][2]:
            print(f'${username}登录成功...')
            exit('bey...')
        else:
            print('密码输入错误')
            errMaxCount-=1


    if errMaxCount==0:
        print('密码输入3次，已锁定')

        users[username][3] = '1'

        f2 = open('user','w')

        for user,val in users.items():
            line = ' '.join(val)+'\n'
            f2.write(line)

        f2.close()
        exit('bey...')
            

